﻿using System.Threading;
using Amarok.Agents;


namespace Amarok.Samples
{
	/// <summary>
	/// </summary>
	public sealed class MyFirstAgent : MyAgentBase<MyFirstAgentOptions>
	{
		private readonly Timer mTimer;


		/// <summary>
		/// </summary>
		public MyFirstAgent(MyEnvironment environment, MyFirstAgentOptions options)
			: base(environment, options)
		{
			mTimer = new Timer(state =>
				{
					base.Publish(new TickMessage());
				});
		}


		/// <summary>
		/// </summary>
		protected override void OnCleanup()
		{
			mTimer.Dispose();
		}


		[InformationHandler, ExclusiveExecution]
		private void _HandleApplicationStarted(ApplicationStarted information)
		{
			mTimer.Change(0, base.Options.Interval);
		}

	}
}
